﻿using Sunboxsoft.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sunboxsoft.ASMS.Server.Domain.Service
{
    public class DeliverService
    {
        public ServiceResult DeliverMaintenanceBill(Guid maintenanceBillId)
        {
            using (ASMSDbContext dbContext = new ASMSDbContext())
            {
                Entity.EMaintenanceBill bill = dbContext.Set<Entity.EMaintenanceBill>().SingleOrDefault(p => p.Id == maintenanceBillId);
                if(bill== null)
                {
                    return new ServiceResult(1, "bill not exist!");
                }

                bill.Status = Constant.MaintenanceBillStatus.Finished;
                dbContext.Entry<Entity.EMaintenanceBill>(bill).State = System.Data.Entity.EntityState.Modified;
                try
                {
                    dbContext.SaveChanges();
                    return new ServiceResult();
                }
                catch (Exception ex)
                {
                    Logger.ErrorToTag(Library.LogTag, string.Format("DeliverAutomobile error,ex:{0}", ex));
                    return new ServiceResult(1, ex.Message);
                }
            }
        }
    }
}
